package mypaint;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.SeekBar;

import com.example.johnsun.mytestapp.R;


/**
 * Created by JohnSun on 2016/1/30.
 */
public class PaintPWindow {
 public Context context;
 public View view ;
    private Circle circle;
    public PaintPWindow(Context context,View view){
        this.view=view;
        this.context =context;
        circle=new Circle(context);

    }

    public void show(){



        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(context).inflate(
                R.layout.poupwindow_paint, null);
        // 设置按钮的点击事件
        SeekBar seekBar = (SeekBar) contentView.findViewById(R.id.seekBar_paint);
        LinearLayout linearLayout = (LinearLayout) contentView.findViewById(R.id.ll);
        linearLayout.removeAllViews();
        linearLayout.addView(circle);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {



            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });



        final PopupWindow popupWindow = new PopupWindow(contentView,
                300, 80, true);

        popupWindow.setTouchable(true);


        // 如果不设置PopupWindow的背景，无论是点击外部区域还是Back键都无法dismiss弹框
        // 我觉得这里是API的一个bug
        popupWindow.setBackgroundDrawable(context.getResources().getDrawable(
                R.drawable.paint_bg));



        // 设置好参数之后再show
        popupWindow.showAsDropDown(view,100,-50);







    }


}
